﻿using Mysoft.Data.Repository;
using Mysoft.Entity.Basic;

namespace Mysoft.Data
{
    /// <summary>
    /// 注入实体服务
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class EntityService<TEntity> where TEntity : EntityBase
    {
        /// <summary>
        ///  注入全局实例
        /// </summary>
        /// <param name="instance"></param>
        public EntityService(IServiceProvider serviceProvider)
        {
            if (_Instance == null)
            {
                _Instance = serviceProvider;
            }
        }
        /// <summary>
        /// 全局实例对象
        /// </summary>
        private static IServiceProvider _Instance { get; set; }

        public IRepository<TEntity> Instance
        {
            get { return _Instance.GetService(typeof(IRepository<TEntity>)) as IRepository<TEntity>; }

        }
    }
}
